package com.mxpio.erp.quality.service.impl;

import com.mxpio.erp.common.quality.entity.SoInQualityOrderLine;
import com.mxpio.erp.common.quality.entity.VEInspectionBillAssemblyProblem;
import com.mxpio.erp.common.quality.entity.VEInspectionBillPassRate;
import com.mxpio.erp.common.quality.service.SoInQualityOrderLineService;
import com.mxpio.erp.common.quality.service.VEInspectionBillAssemblyProblemService;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.jpa.lin.Linq;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.security.entity.Dept;
import com.mxpioframework.system.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class VEInspectionBillAssemblyProblemServiceImpl extends BaseServiceImpl<VEInspectionBillAssemblyProblem> implements VEInspectionBillAssemblyProblemService {
    @Override
    @Transactional(readOnly = true)
    public List<Map<String, Object>> getTOP10(Criteria criteria) {
        String sql ="SELECT year_month_,\n" +
                "num_questions_,\n" +
                "item_name_,\n" +
                "drawing_no_\n" +
                "FROM V_MB_ERP_INSPECTION_BILL_ASSEMBLY_PROBLEM  \n" +
                "ORDER BY NUM_QUESTIONS_ DESC  \n" +
                "LIMIT 10;";
        List<Object[]> resultList = JpaUtil.nativeQuery(sql).getResultList();
        if (resultList == null){
            List<Map<String, Object>> list = new ArrayList<>();
            return list;
        }
        List<Map<String, Object>> arrayList = new ArrayList<>();// 存map中的数据
        for (Object[] row : resultList) {
            Map<String, Object> map = new HashMap<>();// 将数据转成键值格式对存入map
            String yearMonth = (String) row[0];
            String numQuestions = row[1].toString();
            String itemName = (String) row[2];
            String drawingNo = (String) row[3];
            map.put("yearMonth", yearMonth);
            map.put("numQuestions", numQuestions);
            map.put("itemName", itemName);
            map.put("drawingNo", drawingNo);
            arrayList.add(map);
        }
        return arrayList;
    }
}
